package cn.djp.canting.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.TextView;

import org.litepal.LitePal;

import cn.djp.canting.R;
import cn.djp.canting.bean.AllFood;

//导引页
public class IndexActivity extends AppCompatActivity {
    private TextView textView;
    private Handler  mHandler;
    private Runnable mRunnable;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_index);
        //创建数据库
        LitePal.getDatabase();

        //将全部餐品添加至数据库
        AllFood.setOrder();
        iniv();
        HandlerTZ();   // handler 3秒后自动跳转login

        //跳过按钮跳转
        textView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(IndexActivity.this,LoginActivity.class);
                startActivity(intent);
                //停止延时跳转
                mHandler.removeCallbacks(mRunnable);
                finish();
            }
        });

    }
    //延时跳转
    private void HandlerTZ() {
        mRunnable = new Runnable() {
            @Override
            public void run() {
                Intent intent = new Intent(IndexActivity.this,LoginActivity.class);
                startActivity(intent);finish();
                finish();
            }
        };
       mHandler = new Handler();
        mHandler.postDelayed(mRunnable,3000);
    }

    private void iniv() {
        textView = findViewById(R.id.tv_1);
    }
}
